home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / UTILITY / CMDED2E6.ARJ / INSTALL.ASM < prev    next >
Assembly Source File  |  1992-06-30  |  29KB  |  962 lines

  1. ; INSTALL.ASM
  2. ; (c) 1989, 1990 Ashok P. Nadkarni
  3. ; Addition of /c,l,w,o,t & z options by David Abbott (dfa),  Nov-Dec, 1990.
  4. ; Improvements to locate_cmdedit by dfa,  Jan 1991.
  5. ; also /k option added May 1991 and /n added July 1991.
  6. ; /a and /y options added by dfa and wd,  and /x by wd June 1992.
  7. ;
  8. ; This code is the installation code for CMDEDIT. This file must be
  9. ; linked last !
  10.  
  11.     INCLUDE common.inc
  12.     INCLUDE ascii.inc
  13.     INCLUDE dos.inc
  14.     INCLUDE general.inc
  15.  
  16.     PUBLIC    install_begin
  17.     PUBLIC    install
  18.     PUBLIC    file_error
  19.     PUBLIC    abort_install
  20.     PUBLIC    dirstk_error
  21.     PUBLIC    process_args
  22.  
  23. CSEG    SEGMENT    PARA PUBLIC 'CODE'
  24.     EXTRN    getargs:PROC
  25.     EXTRN    cmdlen:BYTE
  26.     EXTRN    default_imode:BYTE
  27.     EXTRN    auto_recall:BYTE
  28.     EXTRN    pgm_name:BYTE
  29.     EXTRN    silent:BYTE
  30.     EXTRN    macrosize:WORD
  31.     EXTRN    macro_ignore_char:BYTE
  32.     EXTRN    symsize:WORD
  33.     EXTRN    dossize:WORD
  34.     EXTRN    dirsize:WORD
  35.     EXTRN    mfilename:BYTE
  36.     EXTRN    mfile_seen:BYTE
  37.     EXTRN    prev_isr1b:WORD
  38.     EXTRN    enable_dircmds:BYTE
  39.     EXTRN    dos_version_major:BYTE
  40.     EXTRN    dos_version_minor:BYTE
  41.     EXTRN    old_int21vec:WORD
  42.     EXTRN    cmdedit:PROC
  43.     EXTRN    our_break_handler:PROC
  44.     EXTRN    init_over:PROC
  45.     EXTRN    cmdedit_isr:PROC
  46.     EXTRN    getkey_funcnum:BYTE
  47. ;dfa added the following
  48.     EXTRN    cursor_type:BYTE
  49.     EXTRN    disable_macro:BYTE
  50.     EXTRN    backslash_char:BYTE
  51.     EXTRN    min_length:WORD
  52.     EXTRN    msg_flag:BYTE
  53.     EXTRN    cmdedit_disable:BYTE
  54.     EXTRN    TAB_key_function:WORD
  55.     EXTRN    ESC_key_function:WORD
  56.     EXTRN    BKS_key_function:WORD    ; added by wd
  57.  
  58. DGROUP    GROUP    CSEG
  59.  
  60.  
  61.     ASSUME    CS:DGROUP,DS:DGROUP,ES:DGROUP,SS:DGROUP
  62.  
  63. ; install_begin MUST be start of installation code.
  64. install_begin    LABEL BYTE
  65. msg_nomem    db '* Insufficient Memory - Reduce buffer sizes *',CR,LF,DOLLAR
  66. option_error db '* Unknown or illegal options *',CR,LF,DOLLAR
  67. file_error   db '* Error processing command file *',CR,LF,DOLLAR
  68. dirstk_error db '* Error processing directory stack commands *',CR,LF,DOLLAR
  69. inv_dosver   db '* Unsupported DOS version. *',CR,LF,DOLLAR
  70. msg_dup      db '* CMDEDIT already installed in memory. *',CR,LF,DOLLAR
  71. ;dfa added options to next line:
  72. options_dup  db '* Only options /a /c /g /i /l /n /o /p /r /t /z may be specified. *',CR,LF,DOLLAR
  73. msg_notdup   db '* No copy of CMDEDIT found in memory. *',CR,LF,DOLLAR
  74. msg_unload   db '* Unable to unload CMDEDIT.        *',CR,LF
  75.          db '* Uninstall TSRs in reverse order.    *',CR,LF,DOLLAR
  76. msg_memerr   db '* DOS memory allocation error! *',CR,LF,BEL
  77.          db '* Recommend you reboot!        *',CR,LF,BEL,DOLLAR
  78. msg_uninstalled db '* CMDEDIT uninstalled successfully *',CR,LF,DOLLAR
  79. msg_omode    db '* Default overwrite mode enabled. *',CR,LF,DOLLAR
  80. msg_imode    db '* Default insert mode enabled. *',CR,LF,DOLLAR
  81. msg_enable_autorecall  db '* autorecall enabled. *',CR,LF,DOLLAR
  82. msg_disable_autorecall db '* autorecall disabled. *',CR,LF,DOLLAR
  83. msg_enable_bell  db '* error bell enabled. *',CR,LF,DOLLAR
  84. msg_disable_bell db '* error bell disabled. *',CR,LF,DOLLAR
  85. msg_ignore_char  db '* ignore character changed. *',CR,LF,DOLLAR
  86. ;following added by dfa
  87. ;(also removed the word "CMDEDIT" from begining of above 5 strings :
  88. msg_dcursor_type   db '* default cursor types. *',CR,LF,DOLLAR
  89. msg_scursor_type   db '* insert & overwrite cursors swapped. *',CR,LF,DOLLAR
  90. msg_disable_macro  db '* macro translation disabled. *',CR,LF,DOLLAR
  91. msg_disable_slash  db '* backslash appending disabled. *',CR,LF,DOLLAR
  92. msg_enable_macro   db '* macro translation enabled. *',CR,LF,DOLLAR
  93. msg_length_changed db '* changed minimum history line length. *',CR,LF,DOLLAR
  94. msg_notinst db '* /o specified but CMDEDIT not previously installed. *',CR,LF,DOLLAR
  95. msg_disable db '* CMDEDIT disabled. *',CR,LF,DOLLAR
  96. msg_enable  db '* CMDEDIT enabled. *',CR,LF,DOLLAR
  97.  
  98. cmdedit_seg  dw    0                ;Segment of the first copy
  99. ;                         of CMDEDIT loaded into memory.
  100.  
  101. argflags    dw    0    ;Used to remember what args have been seen.
  102.                 ;dfa changed from db to dw to allow more args.
  103. dosarg        equ    0001h    ;(in most cases so can flag an error if trying
  104. applarg     equ    0002h    ;  to change after installation)
  105. filearg        equ    0004h
  106. dirarg        equ    0008h
  107. macroarg    equ    0010h
  108. symarg        equ    0020h
  109. uninstall_arg    equ    0040h
  110. ignore_arg    equ    0080h
  111. ;added by dfa:
  112. length_arg    equ    0100h
  113. not_inst_arg    equ    0200h
  114. esc_arg     equ    0400h
  115. no_check_arg    equ    0800h
  116. cycle_arg    equ    1000h
  117. raw_arg         equ     2000h
  118.  
  119. argument_buffer db    LINEBUF_SIZE DUP (?)
  120.  
  121. ;    This location is jumped to when the program is run from the DOS
  122. ;    command line. The program parses the input line, takes
  123. ;    appropriate actions, initializes buffers etc. and then TSR's
  124. ;    after taking over interrupt 21h. The memory taken up by the ISEG
  125. ;    segment will then be used for various data buffers since this
  126. ;    code is no longer needed.
  127. install proc    near
  128.     cld            ;Entire program assumes direction flag will
  129. ;                 be cleared
  130.  
  131.     ASSUME CS:DGROUP,DS:DGROUP,ES:DGROUP,SS:DGROUP
  132.     @DispStr pgm_name        ;Display program name
  133.  
  134. ; Make sure we are running DOS 2.x or higher
  135.     call    near ptr get_dosversion
  136.     cmp    dos_version_major,1        ;DOS 1.x ?
  137.     jne    @install_1
  138.     @DispStr inv_dosver
  139.     mov    ax,-1
  140.     jmp    abort_install            ;V1.x not supported.
  141.  
  142. @install_1:
  143. ; Locate the segment of the first copy of CMDEDIT in memory so that
  144. ; we can tell if this is a second copy.
  145.     call    near ptr locate_cmdedit
  146.     mov    cmdedit_seg,ax            ;Remember it
  147.  
  148. @install_5:
  149.     mov    si,offset cmdlen ;
  150.     lodsb            ;SI == line in PSP, AL == line length
  151.     mov    cl,al
  152.     xor    ch,ch        ;CX = line length
  153.     xor    ax,ax        ;Function = get argument count
  154.     push    cx        ;Save line length
  155.     call     near ptr getargs ;AX := # arguments in command line
  156.     pop    cx        ;Restore line length
  157.     mov    di,ax        ; DI == number of arguments
  158.     inc    di        ;Prime for loop
  159. @install_10:
  160.     dec    di        ;Any more arguments ?
  161.     jz    @install_20    ;No
  162.     mov    bx,offset DGROUP:argument_buffer
  163.     mov    dx,SIZE argument_buffer
  164.     mov    ax,di        ;Argument number
  165.     push    cx        ;save line length
  166.     call     near ptr getargs ;Get argument into argument_buffer
  167. ;                  (no chance of buffer being too short)
  168.     call     near ptr process_args ;Process the argument
  169.     pop    cx        ;Restore line length
  170.     jmp    short @install_10 ;loop back to process remaining args
  171.  
  172.  
  173. @install_20:
  174. ; OK now we have done all necessary parsing without errors. Now first check
  175. ; if the uninstall option was specified.
  176.     test    argflags,uninstall_arg
  177.     je    @install_21        ;Nope
  178.  
  179. ; We have to unload a previously installed copy of CMDEDIT. See if it is
  180. ; really there.
  181.     mov    ax,ds            ;Are we the only copy of CMDEDIT ?
  182.     cmp    ax,cmdedit_seg
  183.     je    @install_20_a        ;There is no other copy
  184.     jmp    uninstall
  185.  
  186. @install_20_a:
  187.     @DispStr msg_notdup        ;Indicate no copy to uninstall
  188.     mov    ax,-1
  189.     jmp    abort_install        ;Exit 
  190.  
  191. @install_21:
  192. ; No uninstall option specified. Now check if this is the only copy of
  193. ; CMDEDIT.
  194.     test    argflags,no_check_arg  ;is checking disabled? (added by dfa)
  195.     jnz    @install_21_a1
  196.     mov    ax,ds
  197.     cmp    ax,cmdedit_seg
  198.     je    @install_21_a1        ;We are the only copy. Proceed with
  199. ;                     installation 
  200.     jmp    change_installed_options ;Else go change installed options.
  201.  
  202. @install_21_a1:             ;added by dfa
  203.     mov    cmdedit_seg,ds        ;in case /n specified.
  204.     test    argflags,not_inst_arg    ;Do we want to install or not?
  205.     jz    @install_21_a
  206.     @DispStr msg_notinst        ;Indicate no copy installed to change.
  207.     mov    ax,-1
  208.     jmp    abort_install        ;Exit
  209.  
  210. @install_21_a:
  211. ; At this point all the arguments have been parsed. Now check
  212. ; that the sum total of the various buffer sizes does not exceed
  213. ; segment limits. Also check for mandatory minimum sizes.
  214. ; Finally, transfer control to the resident portion which will
  215. ; relocate buffers to overlay the installation code.
  216.  
  217.     mov    ax,OFFSET DGROUP:install_begin
  218.                     ;add starting address where buffers
  219.                     ; will begin
  220.     add    ax,STACK_SIZE
  221.     jnc    @install_23
  222.     jmp    @install_125
  223. @install_23:
  224.     cmp    macrosize,MACROSIZE_MIN
  225.     jnb    @install_22
  226.     mov    macrosize,MACROSIZE_MIN ;Ensure min buffer sizes
  227. @install_22:
  228.     add    ax,macrosize
  229.     jc    @install_125
  230.     cmp    symsize,SYMSIZE_MIN
  231.     jnb    @install_24
  232.     mov    symsize,SYMSIZE_MIN ;Ensure min buffer sizes
  233. @install_24:
  234.     add    ax,symsize
  235.     jc    @install_125
  236.     cmp    dossize,DOSSIZE_MIN
  237.     jnb    @install_26
  238.     mov    dossize,DOSSIZE_MIN ;Ensure min buffer sizes
  239. @install_26:
  240.     add    ax,dossize
  241.     jc    @install_125
  242.     cmp    dirsize,DIRSIZE_MIN
  243.     jnb    @install_30
  244.     mov    dirsize,DIRSIZE_MIN ;Ensure min buffer sizes
  245. @install_30:
  246.     add    ax,dirsize
  247.     jc    @install_125
  248. ;Enough memory, so keep resident. Install our Ctrl-Break handler.
  249.     push    es            ;Save ES
  250.     mov    ah,35h
  251.     mov    al,1bh            ;Ctrl-Break Interrupt
  252.     int    21h            ;Get current handler address
  253.     mov    CS:prev_isr1b,bx    ;Offset of previous handler
  254.     mov    CS:prev_isr1b+2,es    ;Segment of previous handler
  255.     pop    es            ;Restore es
  256.     mov    dx,offset CS:our_break_handler
  257.     push    ds            ;Save DS
  258.     mov    ax,cs
  259.     mov    ds,ax            ;DS:DX->our break handler
  260.     mov    al,1bh
  261.     mov    ah,25h            ;Set up our break handler
  262.     int    21h
  263.     pop    ds            ;Restore DS
  264. ;
  265.     jmp    near ptr init_over
  266.  
  267.  
  268.  
  269. @install_125:
  270.     @DispStr msg_nomem
  271.     mov    ax,-1
  272.     jmp    abort_install
  273.  
  274. install endp
  275.  
  276.  
  277.  
  278.  
  279. ;+
  280. ; FUNCTION : process_args
  281. ;
  282. ;    Processes the argument pointed to by BX. AX contains length 
  283. ;    of argument. If a previously seen argument is repeated, it is
  284. ;    ignored (ie. the old value is kept). Note that the argument is
  285. ;    assumed not to contain any delimiters (like space or tab).
  286. ;
  287. ;    Options start with either a '-' or '/'. Any associated value must
  288. ;    follow immediately after without any intervening space/tab.
  289. ;        /f    Macro file to be read.
  290. ;        /l    (added by dfa) min. command length to store in buffer
  291. ;        /d    DOS history buffer size
  292. ;        (/a)    Application history buffer size (only if
  293. ;            separate histories maintained) (OUTDATED)
  294. ;        /a    (added by dfa) Now a toggle for backslash appending
  295. ;        /m    Macro buffer size
  296. ;        /b    symbol buffer size
  297. ;        /s    Directory Stack size
  298. ;        /r    Auto recall mode
  299. ;        /i    Insert mode default
  300. ;        /c    (added by dfa) Reverse cursor type for insert/overtype
  301. ;        /k    (added by dfa) ESC key also used for filenme completion
  302. ;        /t    (added by dfa) Disable macro and symbol translation
  303. ;        /g    Silent mode
  304. ;        /p    macro ignore character
  305. ;        (/e)    Enable dir commands all the time (OUTDATED)
  306. ;        /u    Uninstall CMDEDIT
  307. ;        /x    use raw read mode for keystrokes
  308. ;        /y    tab cYcles through matching files (swapped with Ctrl-\)
  309. ;
  310. ;
  311. ;    Invalid options result in program abortion. If an option is not
  312. ;    followed by a value, the default value for the option is assumed.
  313. ;
  314. ;    Note that this is NOT a general purpose getopt type routine.
  315. ;
  316. ; Parameters:
  317. ;    BX    = Pointer to argument
  318. ;    AX    = Number of characters in argument
  319. ;
  320. ; Returns:
  321. ;    Nothing.
  322. ;    Various globals may be set according to the specified argument.
  323. ; Register(s) BX (call to aton),CX  are destroyed.
  324. ;-
  325. process_args proc near
  326.     @save    si,di
  327.     test    argflags,uninstall_arg
  328.     jne    @process_args_5    ;If /U specified, no other arg is allowed
  329.  
  330.     xchg    ax,cx        ;CX = character count
  331.     sub    cx,2        ;Delete switch char and option letter
  332.     jb    @process_args_5    ;Error in option specification
  333.                 ;  if num chars less than 2
  334.     mov    si,bx        ;SI = arg buffer address
  335.     lodsb            ;AL = first character
  336.     cmp    al,'/'        ;Should be either '/'
  337.     je    @process_args_10 ;
  338.     cmp    al,'-'        ; or '-'
  339.     jne    short @process_args_5    ;Else error
  340.  
  341. @process_args_10:            ;Saw a valid switch char
  342.     lodsb                ;AL = option letter
  343.     or    al,32            ;Lowercase (non alphabetic will be
  344.                     ; ignored anyway)
  345.     cmp    al,'u'            ;Uninstall option ?
  346.     jne    @process_args_13    ;No
  347.     or    cx,cx            ;Ok if no more chars in arg
  348.     jne    short @process_args_5    ;Else error
  349.  
  350. @process_args_11:
  351.     or    argflags,uninstall_arg    ;Indicate /U seen
  352.     jmp    @process_args_50    ;Return
  353.  
  354. ; process_args_13 added by dfa
  355. @process_args_13:
  356.     cmp    al,'c'            ;swap cursor types option ?
  357.     jne    @process_args_13b    ;No
  358.     jcxz    @process_args_13_a    ;Ok if no more chars in arg
  359.     jmp    short @process_args_5    ;Else error
  360. @process_args_13_a:
  361.     mov    cursor_type,1        ;Swap insert/overtype cursor mode
  362.     jmp    @process_args_50    ;Return
  363.  
  364. @process_args_13b:
  365.     cmp    al,'k'            ;Use ESC key for filename completion
  366. ;                     (as well as TAB)
  367.     jne    @process_args_11_a    ;No
  368.     jcxz    @process_args_13b_a    ;Ok if no more chars in arg
  369.     jmp    short @process_args_5    ;Else error
  370. @process_args_13b_a:
  371.     mov    cx,BKS_key_function
  372.     mov    ESC_key_function,cx    ;Make ESC do same as Ctrl-\
  373.     or    argflags,esc_arg    ;Remember we've seen this option
  374.     jmp    @process_args_50    ;Return
  375.  
  376. @process_args_11_a:
  377.     cmp    al,'i'            ;insert mode option ?
  378.     jne    @process_args_14    ;No
  379.     jcxz    @process_args_12    ;Ok if no more chars in arg
  380. @process_args_5:
  381. ; Error processing
  382.     @DispStr option_error
  383.     mov    ax,-1
  384.     jmp    abort_install
  385. @process_args_12:
  386.     mov    default_imode,1        ;Change default insrt mode
  387.     jmp    @process_args_50    ;Return
  388.  
  389. @process_args_14:
  390.     cmp    al,'g'            ;silent mode option ?
  391.     jne    @process_args_15    ;No
  392.     jcxz    @process_args_14_a    ;Ok if no more chars in arg
  393.     jmp    short @process_args_5    ;Else error
  394. @process_args_14_a:
  395.     mov    silent,1        ;Silent mode
  396.     jmp    @process_args_50    ;Return
  397. @process_args_15:
  398.     cmp    al,'r'            ;auto-recall option ?
  399.     jne    @process_args_18    ;No
  400.     jcxz    @process_args_16    ;Ok if no more chars in arg
  401.     jmp    short @process_args_5    ;Else error
  402. @process_args_16:
  403.     mov    auto_recall,1        ;Set auto-recall mode
  404.     jmp    @process_args_50    ;Return
  405. @process_args_18:
  406.     cmp    al,'e'            ;Enable dir commands option?
  407.     jne    @process_args_18_b    ;No
  408.     jcxz    @process_args_18_a    ;OK if no more chars
  409.     jmp    short @process_args_5    ;Else error
  410. @process_args_18_a:
  411.     mov    enable_dircmds,1    ;enable directory commands
  412.     jmp    @process_args_50    ;Return
  413. @process_args_18_b:
  414.     cmp    al,'p'            ;ignore character option
  415.     jne    @process_args_18_c
  416.     cmp    cx,1            ;Should be only one more char
  417.     jne    @process_args_5        ;Error
  418.     lodsb
  419.     or    argflags,ignore_arg    ;Indicate that an ignore char set
  420.     mov    macro_ignore_char,al
  421.     jmp    @process_args_50    ;Return
  422. @process_args_18_c:            ;added by dfa
  423.     cmp    al,'t'            ;disable macro and symbol translation
  424.     jne    @process_args_18_e
  425.     jcxz    @process_args_18_d    ;OK if no more chars
  426.     jmp    short @process_args_5    ;Else error
  427. @process_args_18_d:            ;added by dfa
  428.     mov    disable_macro,1     ;disable
  429.                     ;will toggle option later if installed
  430.     jmp    @process_args_50    ;Return
  431. @process_args_18_e:            ;added by dfa
  432.     cmp    al,'w'            ;alternate error message display
  433.     jne    @process_args_18_g
  434.     jcxz    @process_args_18_f    ;OK if no more chars
  435.     jmp    short @process_args_5    ;Else error
  436. @process_args_18_f:            ;added by dfa
  437.     mov    msg_flag,1        ;disable
  438. ;                     will toggle option later if installed
  439.     jmp    @process_args_50    ;Return
  440. @process_args_18_g:            ;added by dfa
  441.     cmp    al,'o'            ;do not install
  442.     jne    @process_args_18_i
  443.     jcxz    @process_args_18_h    ;OK if no more chars
  444.     jmp    @process_args_5     ;Else error
  445. @process_args_18_h:            ;added by dfa
  446.     or    argflags,not_inst_arg
  447.     jmp    @process_args_50    ;Return
  448. @process_args_18_i:            ;added by dfa
  449.     cmp    al,'z'            ;disable CMDEDIT
  450.     jne    @process_args_18_k
  451.     jcxz    @process_args_18_j    ;OK if no more chars
  452.     jmp    @process_args_5     ;Else error
  453. @process_args_18_j:            ;added by dfa
  454.     mov    cmdedit_disable,1; (will toggle option later if installed)
  455.     jmp    @process_args_50    ;Return
  456. @process_args_18_k:            ;added by dfa
  457.     cmp    al,'n'            ;disable CMDEDIT
  458.     jne    @process_args_18_m
  459.     jcxz    @process_args_18_l    ;OK if no more chars
  460.     jmp    @process_args_5     ;Else error
  461. @process_args_18_l:            ;added by dfa
  462.     or    argflags,no_check_arg
  463.     jmp    @process_args_50    ;Return
  464. @process_args_18_m:            ;added by dfa
  465.     cmp    al,'a'            ;disable backslash appending
  466.     jne    @process_args_18_o
  467.     jcxz    @process_args_18_n    ;OK if no more chars
  468.     jmp    @process_args_5     ;Else error
  469. @process_args_18_n:            ;added by dfa & wd
  470.     mov    backslash_char,0
  471.     jmp    @process_args_50    ;Return
  472. @process_args_18_o:            ;added by wd
  473.     cmp    al,'y'            ;cYcle filename completion on TAB
  474.     jne    @process_args_18_q
  475.     jcxz    @process_args_18_p    ;OK if no more chars
  476.     jmp    @process_args_5     ;Else error
  477. @process_args_18_p:
  478.     mov    cx,BKS_key_function    ;Swap TAB and Ctrl-\
  479.     mov    ax,TAB_key_function
  480.     mov    BKS_key_function,ax
  481.     mov    TAB_key_function,cx
  482.     or    argflags,cycle_arg    ;Remember we've seen this option
  483.     test    argflags,esc_arg    ;was /k specified?
  484.     jz    @to_process_args_50    ;no
  485.     mov    ESC_key_function,ax    ;yes, set ESC key also
  486.     jmp    @process_args_50    ;Return
  487. @process_args_18_q:            ;added by wd
  488.     cmp    al,'x'            ;raw input mode
  489.     jne    @process_args_19
  490.     jcxz    @process_args_18_r    ;OK if no more chars
  491.     jmp    @process_args_5     ;Else error
  492. @process_args_18_r:
  493.     mov    getkey_funcnum,7    ;use raw input for getkey call
  494.         or      argflags,raw_arg        ;Remember we've seen this option
  495.     jmp    @process_args_50    ;Return
  496.  
  497. @process_args_19:
  498.     cmp    al,'f'            ;Is it the macro file option ?
  499.     jne    @process_args_20
  500.     test    argflags,filearg    ;Already seen file argument ?
  501.     je    @process_args_19_a    ;No, then update
  502.     jmp    @process_args_50    ;Yes, then don't update
  503. @process_args_19_a:
  504.     or    argflags,filearg    ;Remember we've seen this option
  505. ;    jcxz    @process_args_50    ;(changed to the line below wd)
  506.     jcxz    @to_process_args_50
  507.     cmp    cx,63            ;Max path length must be < 64
  508.     jna    @process_args_19_b    ;dfa changed ja @process_args_5 to
  509. ;                     these 3 lines.
  510.     jmp    @process_args_5     ;Error
  511. @process_args_19_b:
  512.     mov    di,offset mfilename    ;Temp storage for filename
  513.     rep    movsb            ;Copy file name
  514.     mov    byte ptr [di],0        ;Terminate with a NULL char
  515.     mov    mfile_seen,1        ;Indicate that init file specified
  516. @to_process_args_50:
  517.     jmp    @process_args_50    ;(dfa): was a short jump
  518. @process_args_20:
  519.     push    ax            ;Save the option letter
  520.     xchg    ax,cx            ;AX = num of char
  521.     call    near ptr aton        ;All other options are numeric values
  522.     jnc    @process_args_22    ;No Errors
  523.     jmp    @process_args_5     ;Error
  524. @process_args_22:
  525. ;AX contains numeric value
  526.     xchg    ax,cx            ;CX = numeric value
  527.     pop    ax            ;Restore option letter
  528.  
  529. ;next 7 lines added by dfa
  530.     cmp    al,'l'            ;Is it the minimum length option ?
  531.     jne    @process_args_24
  532.     test    argflags,length_arg    ;Already seen argument ?
  533.     jne    @process_args_50    ;Yes, then don't update
  534.     or    argflags,length_arg    ;Remember we've seen this option
  535.     mov    min_length,cx
  536.     jmp    short @process_args_50
  537.  
  538. @process_args_24:
  539.     cmp    al,'d'            ;Is it the dos history size option ?
  540.     jne    @process_args_25
  541.     test    argflags,dosarg     ;Already seen argument ?
  542.     jne    @process_args_50    ;Yes, then don't update
  543.     or    argflags,dosarg     ;Remember we've seen this option
  544.     mov    dossize,cx
  545.     jmp    short @process_args_50
  546.  
  547. @process_args_25:
  548.     cmp    al,'m'            ;Is it the macro buf size option ?
  549.     jne    @process_args_35
  550.     test    argflags,macroarg    ;Already seen argument ?
  551.     jne    @process_args_50    ;Yes, then don't update
  552.     or    argflags,macroarg    ;Remember we've seen this option
  553.     mov    macrosize,cx
  554.     jmp    short @process_args_50
  555.  
  556. @process_args_35:
  557.     cmp    al,'b'            ;Is it the symbol buf size option ?
  558.     jne    @process_args_40
  559.     test    argflags,symarg     ;Already seen argument ?
  560.     jne    @process_args_50    ;Yes, then don't update
  561.     or    argflags,symarg     ;Remember we've seen this option
  562.     mov    symsize,cx
  563.     jmp    short @process_args_50
  564.  
  565. @process_args_40:
  566.     cmp    al,'s'            ;Is it the dir stack option ?
  567.     je    @process_args_55    ;Yes
  568.     jmp    @process_args_5     ;Invalid arg
  569. @process_args_55:
  570.     test    argflags,dirarg     ;Already seen argument ?
  571.     jne    @process_args_50    ;Yes, then don't update
  572.     or    argflags,dirarg     ;Remember we've seen this option
  573.     mov    dirsize,cx
  574.     
  575. @process_args_50:
  576.  
  577.     @restore
  578.     ret
  579. process_args endp
  580.  
  581.  
  582. ;+
  583. ; FUNCTION : aton
  584. ;
  585. ;    Returns the positive integer value of an ASCII string. The value
  586. ;    must be between 0 and 65535. If length of string is 0, then a 0
  587. ;    value is returned with no error flags.
  588. ;
  589. ; Parameters:
  590. ;    SI    := address of first character in string
  591. ;    AX    := count of characters
  592. ;
  593. ; Returns:
  594. ;    AX = 16 bit result if no errors.
  595. ;    CF = 1 if error (magnitude too large, invalid character etc.)
  596. ;         0 if no errors.
  597. ; Register(s) CX,DX  are destroyed.
  598. ;-
  599. aton    proc    near
  600.     @save    si,di
  601.     xor    di,di        ;Result
  602.     xchg    ax,cx        ;CX <- num of chars
  603.     jcxz    @aton_99    ;No chars, result = 0 (CF is also 0)
  604.     cmp    cx,6        ;Shouldn't be more'n 5 chars
  605.     cmc            ;CF=1 if error
  606.     jb    @aton_99    ;Error exit
  607. @aton_10:
  608.     lodsb            ;al = char
  609.     sub    al,'0'        ;Is ASCII value < '0'
  610.     jb    @aton_99
  611.     mov    dx,9        ;Comparison with 9, NOT '9'
  612.     cmp    dl,al
  613.     jb    @aton_99    ;Not valid char
  614.     xor    ah,ah
  615.     inc    dx        ;DX = 10 (multiplier)
  616.     xchg    ax,di        ;ax = result so far
  617.     mul    dx        ;Multiply by 10
  618.     jb    @aton_99    ;Overflow
  619.     add    ax,di        ;Add new character
  620.     jb    @aton_99    ;Overflow
  621.     xchg    ax,di        ;Remember new result in di
  622.     loop    @aton_10    ;Go onto next char
  623. @aton_99:
  624.     xchg    ax,di
  625.     @restore
  626.     ret
  627. aton    endp
  628.  
  629.  
  630. ;+
  631. ; FUNCTION : get_dosversion
  632. ;
  633. ;
  634. ; Stores DOS major and minor versions in dos_version_major and
  635. ; dos_version_minor.
  636. ;-
  637. get_dosversion proc near
  638.     mov    ah,30h
  639.     int    21h
  640.     mov    dos_version_major,al
  641.     mov    dos_version_minor,ah
  642.     ret
  643. get_dosversion endp
  644.  
  645.  
  646.  
  647.  
  648. ;+
  649. ; FUNCTION : abort_install
  650. ;
  651. ;    Called to abort program before installation. Exits to DOS.
  652. ;
  653. ; Parameters:
  654. ;    AL    = Exit code
  655. ;
  656. ; Returns:
  657. ;    Nothing.
  658. ;
  659. ; Register(s) destroyed:
  660. ;    N/A
  661. ;-
  662. abort_install proc near
  663.     @Exit
  664. abort_install endp
  665.  
  666.  
  667.  
  668. ;+
  669. ; FUNCTION : locate_cmdedit
  670. ;
  671. ;    Called to locate the first copy of CMDEDIT loaded into memory. This
  672. ;    is not foolproof in that if CMDEDIT is loaded into high memory
  673. ;    using one of the memory managers like QEMM, it will not be found.
  674. ;
  675. ; Parameters:
  676. ;    None.
  677. ;
  678. ; Returns:
  679. ;    AX - segment of first copy of CMDEDIT in memory.
  680. ;
  681. ; Register(s) destroyed:
  682. ;    <TBA>
  683. ;-
  684. locate_cmdedit proc near
  685.     mov pgm_name, 99 ; Changes first letter 'C' to 'c' so differs from any
  686.              ; copy which may also be in memory due to disk caching
  687.              ; or something similar.  Added by dfa.
  688.     @save    si,di,es
  689. ;    mov    di,offset DGROUP:cmdedit    ;SI and DI will used for
  690. ;Line above replaced by dfa to line below so can change signature in
  691. ;running versions.
  692.     mov    di,offset DGROUP:pgm_name    ;SI and DI will used for
  693.     mov    si,di                ;comparisons
  694.     xor    ax,ax                ;AX will track segments
  695.  
  696. @locate_cmdedit_5:
  697.     mov    es,ax
  698.     push    si                ;Save offsets that are
  699. ;                         compared 
  700.     mov    cx,32                ;Count to be matched
  701.     rep    cmpsb
  702.     pop    si                ;Restore offsets that are
  703. ;                         compared 
  704.     je    @locate_cmdedit_50        ;Matched
  705.     mov    di,si
  706.     inc    ax
  707.     jmp    short @locate_cmdedit_5        ;Try next segment
  708.  
  709. @locate_cmdedit_50:
  710.  
  711.     @restore
  712.     ret
  713. locate_cmdedit endp
  714.  
  715.  
  716. ;+
  717. ; FUNCTION : uninstall
  718. ;
  719. ;    Called to uninstall a previously loaded copy of CMDEDIT.
  720. ;    The routine does not return. It exits CMDEDIT.
  721. ;
  722. ; Parameters:
  723. ;    None.
  724. ;
  725. ; Returns:
  726. ;    None.
  727. ;
  728. ; Register(s) destroyed:
  729. ;    <TBA>
  730. ;-
  731. uninstall proc near
  732. ; Free up the memory occupied by the previous loaded copy of CMDEDIT.
  733. ; First give back the all interrupts that were taken over.
  734.  
  735. ; Make sure no one else has taken over the 1b break handler since we
  736. ; took it over.
  737.     mov    ax,351bh        ;Retrieve current 1b handler
  738.     int    21h
  739.     cmp    bx,offset our_break_handler ;Is the offset the ours ?
  740.     je    @uninstall_20        ;Yes
  741. @uninstall_10:
  742. ; Someone else's taken over the interrupt. Display message and exit.
  743.     @DispStr msg_unload
  744.     mov    ax,-1
  745.     jmp    abort_install
  746. @uninstall_20:
  747.     mov    ax,es            ;Now compare segment
  748.     cmp    ax,cmdedit_seg        ;Is it what we expect?
  749.     jne    @uninstall_10        ;No, display error
  750.  
  751. ; Now check the int 21h handler.
  752.     mov    ax,3521h        ;Retrieve current 1b handler
  753.     int    21h
  754.     cmp    bx,offset cmdedit_isr    ;Is the offset the ours ?
  755.     jne    @uninstall_10        ;No, error
  756.     mov    ax,es            ;Now compare segment
  757.     cmp    ax,cmdedit_seg        ;Is it what we expect?
  758.     jne    @uninstall_10        ;No, display error
  759.  
  760. ; OK, now restore both interrupts
  761.     mov    es,cmdedit_seg        ;ES<-segment of loaded CMDEDIT
  762.     mov    dx,es:prev_isr1b    ;DS:DX->original 1b handler
  763.     mov    ds,es:prev_isr1b+2
  764.     mov    ax,251bh        ;Return int 1b
  765.     int    21h
  766.  
  767.     mov    dx,es:old_int21vec    ;DS:DX->original int 21h handler
  768.     mov    ds,es:old_int21vec+2
  769.     mov    ax,2521h        ;Return int 21
  770.     int    21h
  771.  
  772.     push    cs
  773.     pop    ds            ;Restore DS
  774. ;
  775. ; Finally, return the block of memory taken up by the previous CMDEDIT copy.
  776.     mov    ah,49h            ;Release block function, ES->segment
  777.     int    21h            ;Free the block
  778.     jnc    @uninstall_90        ;No errors
  779.     @DispStr msg_memerr        ;Memory allocation error !
  780.     mov    ax,-1
  781.     jmp    abort_install
  782.  
  783. @uninstall_90:
  784.     @DispStr msg_uninstalled
  785.     xor    ax,ax
  786.  
  787.     @Exit    0            ;Exit to DOS
  788.  
  789. uninstall endp
  790.  
  791.  
  792. ;+
  793. ; FUNCTION : change_installed_options
  794. ;
  795. ;    Called to change settings on a previously installed copy of
  796. ;    CMDEDIT. The function exits to DOS.
  797. ;
  798. ;    This function allows the following options to be toggled or
  799. ;    changed:
  800. ;        /r - toggles autorecall mode
  801. ;        /i - toggles insert mode
  802. ;        /g - toggles silent mode
  803. ;        /p - sets a new ignore character
  804. ;following added by dfa:
  805. ;    /c - swaps cursor type used for insert & overtype modes.
  806. ;    /w - alternate error message display
  807. ;    /l - sets the minimum command line size stored in history buffer
  808. ;    /t - toggles macro and symbol translation off/on
  809. ;    /z - toggles CMDEDIT disable
  810. ;    /y - toggles the tab key's match cYcling (added by wd)
  811. ;
  812. ;If any other option (except /n or /o) is specified, error message is displayed.
  813. ;    
  814. ; Parameters:
  815. ;    None.
  816. ;
  817. ; Returns:
  818. ;    Nothing.
  819. ;
  820. ; Register(s) destroyed:
  821. ;    <TBA>
  822. ;-
  823.  
  824. change_installed_options proc near
  825.     @DispStr msg_dup
  826.     mov    ax,argflags    ;(dfa): was al here, but argflags is now a WORD
  827.                 ;(dfa) added length_arg and not_inst_arg
  828.     and    ax,NOT (ignore_arg + length_arg + not_inst_arg)
  829.     je    @change_installed_options_10
  830. ; Unallowed options specified.
  831.     @DispStr options_dup
  832.     mov    ax,-1
  833.     jmp    abort_install
  834.  
  835. @change_installed_options_10:
  836.     @DispCh LF
  837. ; Change the options specified.
  838.     mov    es,cmdedit_seg        ;ES->segment of previously loaded
  839. ;                     CMDEDIT 
  840. ; First toggle the insert mode option. If /i specified, default_imode will
  841. ; be 1, else 0. Thus just xor it with the memory resident copy to toggle
  842. ; default mode.
  843.     mov    al,es:default_imode
  844.     xor    al,default_imode    
  845.     mov    es:default_imode,al    ;Toggle memory resident option
  846.     or    al,al
  847.     je    @change_installed_options_15
  848.     @DispStr msg_imode
  849.     jmp    short @change_installed_options_17
  850. @change_installed_options_15:
  851.     @DispStr msg_omode
  852.  
  853. @change_installed_options_17:
  854. ;Cursor type toggle (added by dfa)
  855.     mov    al,es:cursor_type
  856.     xor    al,cursor_type
  857.     mov    es:cursor_type,al    ;Toggle memory resident option
  858.     or    al,al
  859.     je    @change_installed_options_18
  860.     @DispStr msg_scursor_type
  861.     jmp short @change_installed_options_19
  862. @change_installed_options_18:
  863.     @DispStr msg_dcursor_type
  864.  
  865. @change_installed_options_19:
  866. ;Disable backslash toggle (added by dfa & wd)
  867.     mov    al,backslash_char
  868.     xor    al,'\'
  869.     xor    al,es:backslash_char
  870.     mov    es:backslash_char,al    ;Toggle memory resident option
  871.     or    al,al
  872.     jnz     short @change_installed_options_20
  873.     @DispStr msg_disable_slash
  874.  
  875. @change_installed_options_20:
  876.     mov    al,es:auto_recall
  877.     xor    al,auto_recall
  878.     mov    es:auto_recall,al    ;Toggle memory resident option
  879.     or    al,al
  880.     jne    @change_installed_options_25
  881.     @DispStr msg_disable_autorecall
  882.     jmp    short @change_installed_options_30
  883. @change_installed_options_25:
  884.     @DispStr msg_enable_autorecall
  885.  
  886. @change_installed_options_30:
  887. ; And now for silent mode
  888.     mov    al,es:silent
  889.     xor    al,silent
  890.     mov    es:silent,al    ;Toggle memory resident option
  891.     or    al,al
  892.     je    @change_installed_options_35
  893.     @DispStr msg_disable_bell
  894.     jmp    short @change_installed_options_40
  895. @change_installed_options_35:
  896.     @DispStr msg_enable_bell
  897.  
  898. @change_installed_options_40:
  899.  
  900. ; Change the ignore character if one was specified.
  901.     test    argflags,ignore_arg
  902.     je    @change_installed_options_50    ;None specified
  903. ; Change to the new macro ignore char
  904.     mov    al,macro_ignore_char
  905.     mov    es:macro_ignore_char,al
  906.     @DispStr msg_ignore_char
  907.  
  908. @change_installed_options_50:
  909. ; And now for macro translation toggle
  910.     mov    al,es:disable_macro
  911.     xor    al,disable_macro
  912.     mov    es:disable_macro,al        ;Toggle memory resident option
  913.     or    al,al
  914.     je    @change_installed_options_55
  915.     @DispStr msg_disable_macro
  916.     jmp    short @change_installed_options_57
  917. @change_installed_options_55:
  918.     @DispStr msg_enable_macro
  919.  
  920. @change_installed_options_57:
  921. ; alternative error message display
  922.     mov    al,es:msg_flag
  923.     xor    al,msg_flag
  924.     mov    es:msg_flag,al        ;Toggle memory resident option
  925.     or    al,al
  926.                 ;not really necessary to confirm this switch.
  927.  
  928. @change_installed_options_60:
  929. ; And now for minimum line length option if one was specified.
  930.     test    argflags,length_arg
  931.     je    @change_installed_options_70    ;None specified
  932.     mov    ax,min_length
  933.     cmp    ax,es:min_length        ;Is new value different to old?
  934.     je    @change_installed_options_70    ;no
  935.     mov    es:min_length,ax        ;Change memory resident value
  936.     @DispStr msg_length_changed
  937.  
  938. @change_installed_options_70:
  939. ; And now for disable CMDEDIT toggle
  940.     mov    al,es:cmdedit_disable
  941.     xor    al,cmdedit_disable
  942.     mov    es:cmdedit_disable,al        ;Toggle memory resident option
  943.     or    al,al
  944.     je    @change_installed_options_75
  945.     @DispStr msg_disable
  946.     jmp    short @change_installed_options_90
  947. @change_installed_options_75:
  948.     @DispStr msg_enable
  949.  
  950. @change_installed_options_90:
  951. ; All done
  952.     @Exit    0
  953.  
  954. change_installed_options endp
  955.  
  956.  
  957.  
  958.  
  959. CSEG    ENDS
  960.  
  961.     END
  962.